配置GRE over IPv4示例(OSPF)

组网需求

  1. Router A、Router B、Router C使用OSPF协议,进程为1
  2. 需要在Router A与Router C之间建立直连链路(部署GRE隧道)
  3. Tunnel接口与用户侧使用OSPFF协议,实现PC1与PC2可以互相通信,进程为2
  4. PC1和PC2分别指定Router A、Router C为自己的缺省网关

组网拓扑

GER over IPv4(OSPF)拓扑图

配置思路

  1. 配置OSPF协议,进程为1,实现Router A、Router B、Router C的互联互通
  2. 配置Tunnel接口,使能接口Tunnel协议为GRE,配置接口地址、源地址、目的地址
  3. 配置Keepalive检测,在Tunnel接口下配置Keepalive检测功能
  4. 源地址为发出报文的物理接口的地址,目的地址为接收报文的物理接口的地址
  5. PC1、PC2与Tunnel隧道建立OSPF协议,进程为2,实现PC1与PC2的互通

配置命令

  1. 配置路由器基本功能以及各个接口IP地址

    • Router A配置

      1
      2
      3
      4
      5
      6
      7
      8
      sys
      sys Router A
      int g0/0/0
      ip add 20.1.1.1 30
      int g0/0/2
      ip add 10.1.1.1 30
      int LoopBack 0
      ip add 1.1.1.1 32
  • Router B配置

    1
    2
    3
    4
    5
    6
    7
    8
    sys
    sys Router B
    int g0/0/0
    ip add 20.1.1.2 30
    int g0/0/1
    ip add 30.1.1.1 30
    int LoopBack 0
    ip add 2.2.2.2 32
  • Router C配置

    1
    2
    3
    4
    5
    6
    7
    8
    sys
    sys Router C
    int g0/0/1
    ip add 30.1.1.2 30
    int g0/0/2
    ip add 10.2.1.1 30
    int LoopBack 0
    ip add 3.3.3.3 32
  1. 配置OSPF协议,实现各个路由器互联互通,进程为1

    • Router A配置

      1
      2
      3
      4
      sys
      ospf 1 router-id 1.1.1.1
      area 0
      network 20.1.1.0 0.0.0.3
  • Router B配置

    1
    2
    3
    4
    5
    sys
    ospf 1 router-id 2.2.2.2
    area 0
    network 20.1.1.0 0.0.0.3
    network 30.1.1.0 0.0.0.3
  • Router C配置

    1
    2
    3
    4
    5
    sys
    ospf 1 router-id 2.2.2.2
    area 0
    network 20.1.1.0 0.0.0.3
    network 30.1.1.0 0.0.0.3
  1. 配置Tunnel接口,接口协议为GRE,配置接口IP、接口源地址、目的地址、使能接口Keepalive检测功能

    • Router A配置

      1
      2
      3
      4
      5
      6
      sys
      int Tunnel 0/0/0
      tunnel-protocol gre
      ip add 40.1.1.1 30
      source 20.1.1.1
      destination 30.1.1.1
  • Router C配置

    1
    2
    3
    4
    5
    6
    sys
    int Tunnel 0/0/0
    tunnel-protocol gre
    ip add 40.1.1.2 30
    source 30.1.1.1
    destination 20.1.1.1
  1. 配置OSPF协议,实现PC1与PC2的互联互通,进程为2

    • Router A配置

      1
      2
      3
      4
      5
      sys
      ospf 2 router-id 1.1.1.1
      area 0
      network 40.1.1.0 0.0.0.3
      network 10.1.1.0 0.0.0.3
  • Router C配置

    1
    2
    3
    4
    5
    sys
    ospf 2 router-id 2.2.2.2
    area 0
    network 40.1.1.1 0.0.0.3
    network 10.2.1.0 0.0.0.3

查看结果

  1. 查看OSPF协议的路由表(进程为1)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    display ip routing-table protocol ospf

    <Router A>dis ip routing-table pro ospf
    Route Flags: R - relay, D - download to fib
    ------------------------------------------------------------------------------
    Public routing table : OSPF
    Destinations : 1 Routes : 1

    OSPF routing table status : <Active>
    Destinations : 1 Routes : 1

    Destination/Mask Proto Pre Cost Flags NextHop Interface

    30.1.1.0/30 OSPF 10 2 D 20.1.1.2 GigabitEthernet
    0/0/0

    OSPF routing table status : <Inactive>
    Destinations : 0 Routes : 0
  1. 查看Tunnel接口状态

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    ping -a 40.1.1.1 40.1.1.2

    <Router A>ping -a 40.1.1.1 40.1.1.2
    PING 40.1.1.2: 56 data bytes, press CTRL_C to break
    Reply from 40.1.1.2: bytes=56 Sequence=1 ttl=255 time=70 ms
    Reply from 40.1.1.2: bytes=56 Sequence=2 ttl=255 time=40 ms
    Reply from 40.1.1.2: bytes=56 Sequence=3 ttl=255 time=20 ms
    Reply from 40.1.1.2: bytes=56 Sequence=4 ttl=255 time=30 ms
    Reply from 40.1.1.2: bytes=56 Sequence=5 ttl=255 time=40 ms

    --- 40.1.1.2 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 20/40/70 ms
  1. 查看Keepalive统计的检测数据包

    1
    2
    3
    4
    5
    6
    7
    8
    display keepalive packets count

    [Router A]int Tunnel 0/0/0
    [Router A-Tunnel0/0/0]display keepalive packets count
    Send 386 keepalive packets to peers, Receive 386 keepalive response packets from
    peers
    Receive 375 keepalive packets from peers, Send 375 keepalive response packets to
    peers.
  1. 查看IP路由表

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    display ip routing-table 10.2.1.2

    <Router A>display ip routing-table 10.2.1.2
    Route Flags: R - relay, D - download to fib
    ------------------------------------------------------------------------------
    Routing Table : Public
    Summary Count : 1
    Destination/Mask Proto Pre Cost Flags NextHop Interface

    10.2.1.0/30 OSPF 10 1563 D 40.1.1.2 Tunnel0/0/0
  1. 测试PC1与PC2之间的连通性

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    ping 10.2.1.2

    <Router A>ping 10.2.1.2
    PING 10.2.1.2: 56 data bytes, press CTRL_C to break
    Request time out
    Reply from 10.2.1.2: bytes=56 Sequence=2 ttl=127 time=20 ms
    Reply from 10.2.1.2: bytes=56 Sequence=3 ttl=127 time=30 ms
    Reply from 10.2.1.2: bytes=56 Sequence=4 ttl=127 time=30 ms
    Reply from 10.2.1.2: bytes=56 Sequence=5 ttl=127 time=20 ms

    --- 10.2.1.2 ping statistics ---
    5 packet(s) transmitted
    4 packet(s) received
    20.00% packet loss
    round-trip min/avg/max = 20/25/30 ms

    tracert 10.2.1.2

    <Router A>tracert 10.2.1.2

    traceroute to 10.2.1.2(10.2.1.2), max hops: 30 ,packet length: 40,press CTRL_C
    to break

    1 40.1.1.2 50 ms 20 ms 20 ms

    2 10.2.1.2 20 ms 30 ms 20 ms
吴超 wechat
subscribe to my blog by scanning my public wechat account